//
//  CNShopCarTableFooterView.m
//  BeeQuick_19
//
//  Created by w on 16/9/23.
//  Copyright © 2016年 CN Team. All rights reserved.
//

#import "CNShopCarTableFooterView.h"
#import "NSString+Extension.h"
#import "CNComitOrderTableViewController.h"
#import "UIView+CNViewController.h"
#import "CNNavViewController.h"
#import "CNGoodsModel.h"
@interface CNShopCarTableFooterView()
@property(nonatomic,strong) UILabel *priceLable;
@property(nonatomic,strong) UIButton *sureButton;

@end
@implementation CNShopCarTableFooterView
 //重写init方法
- (instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        _priceLable = [[UILabel alloc]init];
        _priceLable.textColor = [UIColor redColor];
        _priceLable.font = [UIFont systemFontOfSize:15];
        [self addSubview:_priceLable];
        
        _sureButton = [[UIButton alloc]init];
        _sureButton.backgroundColor = [UIColor colorWithRed:253/255.0 green:212/255.0 blue:49/255.0 alpha:1.0];
        [_sureButton setTitle:@"选好了" forState:UIControlStateNormal];
        _sureButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [_sureButton addTarget:self action:@selector(sureButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_sureButton];
        //约束布局
        [_priceLable mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.equalTo(self).offset(15);
            make.centerY.equalTo(self);
            make.width.mas_equalTo(100);
            make.height.equalTo(self);
        }];
        
        [_sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.trailing.equalTo(self);
            make.top.equalTo(self);
            make.bottom.equalTo(self);
            make.width.mas_equalTo(90);
        }];
    }
    return self;
}
//按钮的点击事件
- (void)sureButtonClicked:(id)sender{
    if(self.sureButtonClicked){
        self.sureButtonClicked();
    }
    NSLog(@"跳转成功");
}
//重写价格set方法并重新设置价格显示
- (void)setPartner_price:(CGFloat)partner_price{
    
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        NSArray *array = [[SQLiteManager sharedSQLiteManager] queryContact];
        float total = 0;
        
        for (CNGoodsModel *model in array) {
            total += model.partner_price*model.count;
        }

        self.priceLable.text = [NSString stringWithFormat:@"总计 %.2f",total];
    });

    
    
}


@end
